package top.goldenyear.porpoise.dev.code.controller.admin;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import lombok.extern.slf4j.Slf4j;
import org.noear.solon.annotation.*;
import top.goldenyear.porpoise.common.core.model.Ret;
import top.goldenyear.porpoise.dev.code.model.CodeColumn;
import top.goldenyear.porpoise.dev.code.service.CodeColumnService;
import top.goldenyear.porpoise.framework.web.core.controller.BaseController;
import top.goldenyear.porpoise.framework.web.core.model.query.QPage;

/**
 * 字段配置 Controller 控制层
 *
 * @author airhead
 * @since 2025-02-04
 */
@Api("字段配置")
@Component(tag = "adminApi")
@Mapping("/dev/code/codeColumn")
@Slf4j
public class CodeColumnAdminController extends BaseController {
  @Inject private CodeColumnService service;

  @Post
  @Mapping("create")
  public Ret create(@Body CodeColumn codeColumn) {
    return Ret.okWithData(service.createCodeColumn(codeColumn));
  }

  @Post
  @Put
  @Mapping("update")
  public Ret update(@Body CodeColumn codeColumn) {
    return Ret.okWithData(service.updateCodeColumn(codeColumn));
  }

  @Get
  @Mapping("get")
  public Ret get(@Param Long id) {
    return Ret.okWithData(service.getCodeColumn(id));
  }

  @Post
  @Delete
  @Mapping("delete")
  public Ret delete(@Param Long id) {
    return Ret.okWithData(service.deleteCodeColumn(id));
  }

  @Post
  @Delete
  @Mapping("batchDel")
  public Ret batchDel(@Param List<Long> ids) {
    return Ret.okWithData(service.batchDelCodeColumn(ids));
  }

  @Get
  @Mapping("paginate")
  public Ret paginate(QPage qPage) {
    CodeColumn codeColumn = getBean(CodeColumn.class);
    return Ret.okWithData(service.paginateCodeColumn(qPage, codeColumn));
  }

  @Get
  @Mapping("list")
  public Ret list() {
    CodeColumn codeColumn = getBean(CodeColumn.class);
    return Ret.okWithData(service.listCodeColumn(codeColumn));
  }

  @Get
  @Mapping("simpleList")
  @ApiOperation("简单列表")
  public Ret simpleList() {
    CodeColumn codeColumn = getBean(CodeColumn.class);
    return Ret.okWithData(service.simpleListCodeColumn(codeColumn));
  }

  @Get
  @Mapping("options")
  @ApiOperation("选项列表")
  public Ret options() {
    CodeColumn codeColumn = getBean(CodeColumn.class);
    return Ret.okWithData(service.optionsCodeColumn(codeColumn));
  }
}
